﻿@page "/CatTalk/passages/view/{Id:int}"
<h3>　</h3>
<br />
<div class="site-page-header-ghost-wrapper">
    @if (myPassage == null) {
        <Result Status="404"
            Title="资源未找到（404）"
            Icon=""
            SubTitle="很可能这个资源已经被删除了" />
    } else {
        <PageHeader BackIcon="true" Ghost="false">
            <PageHeaderTitle>@myPassage.Title</PageHeaderTitle>
            <PageHeaderSubtitle>文章详情</PageHeaderSubtitle>
            <PageHeaderExtra>
                <Button Type="@ButtonType.Primary" OnClick="ToUpdate">
                    编辑
                </Button>
            </PageHeaderExtra>
            <PageHeaderContent>
                <Descriptions Size="small" Column="3">
                    <DescriptionsItem Title="创建者" Span="1">@myUsrInfo.Name</DescriptionsItem>
                    <DescriptionsItem Title="性别" Span="1">@myUsrInfo.Gender</DescriptionsItem>
                    <DescriptionsItem Title="联系方式" Span="1"><a>B站@@大千小熊</a></DescriptionsItem>
                    <DescriptionsItem Title="发布时间" Span="1">@DateTime.Now.ToString()</DescriptionsItem>
                    <DescriptionsItem Title="个性签名" Span="12">@myUsrInfo.Description</DescriptionsItem>
                </Descriptions>
            </PageHeaderContent>
        </PageHeader>
        <br />
        <Vditor.Preview @key="302141" Anchor Markdown="@myPassage.Body"></Vditor.Preview>
    }
</div>
@inject NavigationManager _NavManger;
@code {
    //https://zhuanlan.zhihu.com/p/359102019
    [Parameter]
    public int ID { get; set; } = 0;

    Passage? myPassage { get; set; } = new Passage() { Title = "文章正在加载中", Body = "请再次刷新一下页面" };
    UsrInfo myUsrInfo { get; set; } = new UsrInfo() { Name = "加载中", Description = "加载中" };

    protected override async Task OnInitializedAsync() {
        var myPassage = await GobalManager.getPassageById(ID);
        if (myPassage != null) {
            var getUsrInfo = await GobalManager.GetUsrInfoById(myPassage.UsrId);
            if (getUsrInfo != null) myUsrInfo = getUsrInfo;
        }
        SetValue(myPassage, myUsrInfo);
        await base.OnInitializedAsync();
    }

    void SetValue(Passage? p, UsrInfo u) {
        this.myPassage = p;
        this.myUsrInfo = u;
        StateHasChanged();
        //SetPassageDelay();
    }

    async void SetPassageDelay() {
        await Task.Delay(400);
        if (this.myPassage != null) this.myPassage.Body = "哈哈哈";
        SetValue(myPassage, myUsrInfo);
    }

    void ToUpdate() {
        if (myPassage != null) {
            _NavManger.NavigateTo(@"/CatTalk/Passages/update/" + myPassage.Id);
        }
    }
}
